package com.imc.griebeler.prs;

import static com.imc.griebeler.prs.Symbol.PAPER;
import static com.imc.griebeler.prs.Symbol.ROCK;
import static com.imc.griebeler.prs.Symbol.SCISSORS;

import java.util.HashMap;
import java.util.Map;

public class PaperRockScissorsGame {

	private Map<Symbol, Symbol> winningGuessKey;
	
	public PaperRockScissorsGame() {
		winningGuessKey = new HashMap<Symbol, Symbol>();
		winningGuessKey.put(PAPER, ROCK);
		winningGuessKey.put(ROCK, SCISSORS);
		winningGuessKey.put(SCISSORS, PAPER);
	}
	
	public Player guess(PlayerGuess playerOne, PlayerGuess playerTwo) {
		Symbol playerOneSymbol = playerOne.getGuess();
		Symbol playerTwoSymbol = playerTwo.getGuess();
		
		if(playerOneSymbol.equals(playerTwoSymbol))
			return null;
		else if(winningGuessKey.get(playerOneSymbol).equals(playerTwoSymbol))
			return playerOne.getPlayer();
		else if(winningGuessKey.get(playerTwoSymbol).equals(playerOneSymbol))
			return playerTwo.getPlayer();
		else
			throw new IllegalStateException("No winner could be determined");
	}
}
